package operation.exception;

import operation.util.ReqResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 */
@RestControllerAdvice
public class AppExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(AppException.class)
    public ReqResult handleAppException(AppException e) {
        logger.warn("[OneWarn]: AppExceptionHandler.AppException code: {} errorMessage: {} firstSite: {}", e.getCode(), e.getMessage(), e.getStackTrace()[0].toString());
        ReqResult r = new ReqResult();
        r.put("code", e.getCode());
        r.put("msg", e.getMessage());
        return r;
    }
}
